<template>
  <div ref="sliderRef" class="slider-container">
    <div v-for="(item, index) in flowerSwiuper" :key="index" class="slide-item">
      <div class="slide-item_font1">{{ item.text }}</div>
      <div class="slide-item_font2" @click="go(item.url)">{{ item.text1 }}</div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router'
// 使用 useRouter 创建一个 router 实例
const router = useRouter()
const flowerSwiuper = ref([
  { text: '精选推荐', text1: '送花HOT' },
  { text: '花语大全', text1: '送花HOT', url: "/FlowerLanguage" },
  { text: '文章资讯', text1: '送花HOT', url: "/ArticleVew" },
  { text: '问答解疑', text1: '送花HOT' }
])
const go = (url) => {
  router.push({ path: url })
}
const props = defineProps({
  items: {
    type: Array,
    required: true,
  },
});

const sliderRef = ref(null);

onMounted(() => {
  initSlider();
});

function initSlider() {
  let touchStartX = 0;
  let touchMoveX = 0;

  sliderRef.value.addEventListener('touchstart', (e) => {
    touchStartX = e.touches[0].clientX;
  });

  sliderRef.value.addEventListener('touchmove', (e) => {
    touchMoveX = e.touches[0].clientX;
    if (touchStartX > touchMoveX) {
      // 向右滑动
      slideRight();
    } else if (touchStartX < touchMoveX) {
      // 向左滑动
      slideLeft();
    }
  });
}

function slideRight() {
}

function slideLeft() {
}
</script>

<style lang="scss" scoped>
.slider-container {
  overflow-x: scroll;
  white-space: nowrap;
  scrollbar-width: none;
}

// .slide-item {
//   display: inline-block;
//   width: 200px;
//   height: 200px;
//   border: 1px solid #ccc;
//   text-align: center;
//   line-height: 200px;
//   font-size: 1.5em;
//   margin-right: 1rem;
// }

.slide-item {
  width: 30%;
  padding: 15px;
  border-radius: 10px;
  box-sizing: border-box;
  color: #fff;
  display: inline-block;
  margin-right: 10px;

  .slide-item_font1 {
    font-size: 18px;
    margin-bottom: 5px;
  }

  .slide-item_font2 {
    font-size: 12px;
    color: rgba($color: #fff, $alpha: 0.6);
  }
}

.slide-item:nth-child(1) {
  background-color: #ff8c8c;
}

.slide-item:nth-child(2) {
  background-color: #ff993e;
}

.slide-item:nth-child(3) {
  background-color: #50b2fc;
}
.slide-item:nth-child(4) {
  background-color: #d389f6;
}
</style>
